/*
线段类型

单位均为米(m)

*/

export class BaseShape {
    startPoint: { x: number, y: number };
    constructor(startPoint: { x: number, y: number }) {
        this.startPoint = startPoint;
    }
    // 获取铁轨的终点坐标
    getEndPoint(): { x: number, y: number } {
        throw new Error("Not implemented");
    }
}


export class Line extends BaseShape {
    deltas: { dx: number, dy: number };
    distance: number;
    constructor(startPos: { x: number, y: number }, deltas: { dx: number, dy: number }) {
        super(startPos);
        this.deltas = deltas;
        this.distance = Math.sqrt(deltas.dx * deltas.dx + deltas.dy * deltas.dy);
    }

    public getPoint(
        distance: number): { x: number, y: number } {
        const distanceRatio = distance / this.distance;
        return {
            x: this.startPoint.x + this.deltas.dx * distanceRatio,
            y: this.startPoint.y + this.deltas.dy * distanceRatio
        };
    }

    public getEndPoint(): { x: number, y: number } {
        return { x: this.startPoint.x + this.deltas.dx, y: this.startPoint.y + this.deltas.dy };
    }

}